//
//  ColumnChartViewController.m
//  MoneyLog
//
//  Created by wicresoft on 6/9/11.
//  Copyright 2011 wicresoft. All rights reserved.
//

#import "ColumnChartViewController.h"
#import "ColumnChartView.h"
#import "ColumnChartItem.h"
#import "ColumnChartTitleView.h"

@implementation ColumnChartViewController
@synthesize dataSourceArray;
@synthesize incomeValue,expenseValue,totalValue;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [dataSourceArray release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSString *startDate = [[self.dataSourceArray objectAtIndex:0] title];
    NSString *endDate = [[self.dataSourceArray objectAtIndex:[self.dataSourceArray count]-1] title];
    self.title = [NSString stringWithFormat:@"%@-%@",startDate,endDate];
    
    ColumnChartTitleView *titleView = [[ColumnChartTitleView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    titleView.incomeValue = self.incomeValue;
    titleView.expenseValue = self.expenseValue;
    titleView.totalValue = self.totalValue;
    
    [self.view addSubview:titleView];
    [titleView release];
    
    CGRect viewFrame= CGRectMake(0, 40, 320, 320);
    UIScrollView *chartView = [[UIScrollView alloc] initWithFrame:viewFrame];
    chartView.backgroundColor =[UIColor clearColor];
    chartView.scrollEnabled = YES;
    
    ColumnChartView *view = [[ColumnChartView alloc] initWithFrame:CGRectMake(0, 10, 1000, 310)];
    view.groupData = self.dataSourceArray;
    
    NSLog(@"width=%d",[view getWidth]);
    chartView.contentSize = CGSizeMake([view getWidth], 320);
    [chartView addSubview:view];
    [self.view addSubview:chartView];
    
    [view release];
    [chartView release];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
